﻿using System;

namespace DB
{
    public class DBFactorys
    {
        private static readonly string dbConfig = System.Configuration.ConfigurationManager.AppSettings["dbConfig"];
        private static DBHelpers db = null;
        static string assembly;
        static string typeName;
        public static DBHelpers GetDBHelper()
        {
            if (db == null)
            {
                if (string.IsNullOrEmpty(dbConfig))
                {
                    assembly = typeof(DBFactorys).Module.Name.Substring(0, typeof(DBFactorys).Module.Name.Length - 4);
                    typeName = typeof(DBFactorys).Namespace + ".SQLHelpers";
                }
                if (string.IsNullOrEmpty(assembly))
                    assembly = dbConfig.Split(',')[0];
                if (string.IsNullOrEmpty(typeName))
                    typeName = dbConfig.Split(',')[1];
                db = (DBHelpers)Activator.CreateInstance(assembly, typeName).Unwrap(); //new SQLHelpers();//
                return db;
            }
            else
                return db;
        }
    }
}
